package com.suep.business.service.impl;

import com.suep.business.domain.MealCategory;
import com.suep.business.mapper.MealCategoryMapper;
import com.suep.business.service.IMealCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class MealCategoryImpl implements IMealCategoryService {
    @Autowired
    private MealCategoryMapper mealCategoryMapper;

    @Override
    public MealCategory getById(Integer categoryId) {
        return mealCategoryMapper.selectById(categoryId);
    }

    @Override
    public List<MealCategory> getAll() {
        return mealCategoryMapper.selectAll();
    }

    @Override
    public List<MealCategory> getByStoreId(Integer storeId) {
        return mealCategoryMapper.selectByStoreId(storeId);
    }

    @Override
    public Integer add(MealCategory mealCategory) {
        if (mealCategory.getCreatedAt() == null) {
            mealCategory.setCreatedAt(LocalDateTime.now());
        }
        if (mealCategory.getUpdatedAt() == null) {
            mealCategory.setUpdatedAt(LocalDateTime.now());
        }
        return mealCategoryMapper.insert(mealCategory);
    }

    @Override
    public Integer update(MealCategory mealCategory) {
        mealCategory.setUpdatedAt(LocalDateTime.now());
        return mealCategoryMapper.update(mealCategory);
    }

    @Override
    public Integer deleteById(Integer categoryId) {
        return mealCategoryMapper.deleteById(categoryId);
    }

    @Override
    public Integer deleteByStoreId(Integer storeId) {
        return mealCategoryMapper.deleteByStoreId(storeId);
    }
}
